<?php

/**
 *  广告信息
 *
 * @author LJ <jun.lu.726@gmail.com>
 * @copyright 2012-2013 shangbox.com
 * $Id: Ad.php 162 2012-11-09 04:04:30Z Jun.Lu.726@gmail.com $
 * @history    2012-10-15 16:17:46  ::  Lujun  ::  Create File
 */
class Model_Ad_Ad extends Model_AbstractDao
{

    protected $_dbName     = 'BingoMobi';
    protected $_tableName  = 'bg_ad_Info';
    protected $_primaryKey = 'ad_id';
    protected $_nameField  = 'ad_name';

    /**
     * 获取广告状态
     * @return type
     */
    public function getStates()
    {
        return include (RESOURCE_PATH . 'adState.conf.php');
    }

    /**
     * 获取列表
     * @param string $err
     * @param int $beginTime
     * @param int $endTine
     * @param int $state
     * @param int  $start
     * @param int $pageSize
     * @return array
     */
    public function getList($err, $beginTime, $endTine, $state, $start, $pageSize)
    {
        $sql = "SELECT * FROM `{$this->_tableName}` where 1";
        if (!empty($err)) {
            $sql .= "  AND `create_time` >  '{$beginTime}' AND `create_time` < '{$endTine}'  ";
        }
        if (0 !== $state) {
            $sql .= " AND state = '{$state}' ";
        }
        return $this->_db()->limitQuery($sql, $start, $pageSize);
    }

    /**
     * 获取总数
     * @param string $err
     * @param int $beginTime
     * @param int $endTine
     * @param int $state
     * @return int
     */
    public function getCount($err, $beginTime, $endTine, $state)
    {
        $sql = "SELECT count(0) FROM `{$this->_tableName}` where 1 ";
        if (!empty($err)) {
            $sql .= " AND `create_time` >  '{$beginTime}' AND `create_time` < '{$endTine}'  ";
        }
        if (0 !== $state) {
            $sql .= " AND state = '{$state}' ";
        }
        return $this->_db()->fetchOne($sql);
    }

}